package com.thread.www.demo;

/**
 * Created by wangyang on 2017/11/20.
 */
public class NewThread {
    public static NewThread obj = new NewThread();
    public static class NewThread1 implements Runnable{
        @Override
        public synchronized void run() {
            while (true){
                try {
                    synchronized (obj){
                        obj.wait();
                    }
                }catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("自定义的线程1执行。。。。。");
            }
        }
    }

//    public static class NewThread2 implements Runnable{
//        @Override
//        public  void run() {
//            while (true){
//                try {
//                    synchronized (obj){
//                        wait();
//                    }
//
//                }catch (InterruptedException e) {
//                    e.printStackTrace();
//                }
//                System.out.println("自定义的线程2执行。。。。。");
//            }
//        }
//    }

    public static void main(String[] args) {
        NewThread1 n = new NewThread1();
        Thread t1 = new Thread(n);
//        NewThread2 n1 = new NewThread2();
//        Thread t2 = new Thread(n1);
        t1.start();
//        t2.start();
        while(true){
            System.out.println("主线程运行");
            synchronized (obj){
                obj.notifyAll();
            }
        }
    }
}
